package edu.neusoft.yuejian_09.model;

import java.util.List;

import edu.neusoft.yuejian_09.base.Constant;
import edu.neusoft.yuejian_09.base.RetrofitBaseModel;
import edu.neusoft.yuejian_09.base.RetrofitListener;
import edu.neusoft.yuejian_09.bean.Show;
import edu.neusoft.yuejian_09.service.ShowService;
import okhttp3.MultipartBody;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created by 爽 on 2017/10/16.
 */

public class ShowModel  extends RetrofitBaseModel {
    private int flag;
    public ShowService showService;
    public ShowModel(){
        this.showService=retrofit.create(ShowService.class);
    }

    public void showlist( final RetrofitListener listener){
        ShowService showService=retrofit.create(ShowService.class);
        Call call=showService.getAllShows();
        Callback<List<Show>> callback=new Callback<List<Show>>(){
            @Override
            public void onResponse(Call<List<Show>> call, Response<List<Show>> response ){
                List<Show> data=response.body();
                listener.onSuccess(data,0);//userId这里有问题
            }
            @Override
            public  void onFailure(Call<List<Show>> call, Throwable t){
                listener.onFail();
            }
        };
        call.enqueue(callback);
    }

    //获取晒图详情
    public void getShowById(int Show_id, final RetrofitListener listener){
        Call call=showService.getShowById(Show_id);
        bindCallback(call,listener, Constant.SHOWBYID);
    }

    /*获取晒图列表根据用户*/
   /* public void getShowByUser(int User_id, final RetrofitListener listener){
        ShowService showService=retrofit.create(ShowService.class);
        Call call=showService.getShowByUId(User_id);
        Callback<List<Show>> callback=new Callback<List<Show>>(){
            @Override
            public void onResponse(Call<List<Show>> call, Response<List<Show>> response ){
                List<Show> data=response.body();
                listener.onSuccess(data,1);//userId这里有问题
            }
            @Override
            public  void onFailure(Call<List<Show>> call, Throwable t){
                listener.onFail();
            }
        };
        call.enqueue(callback);
    }*/
    public void getShowByUser(int User_id, final RetrofitListener listener){
        Call call=showService.getShowByUId(User_id);
        bindCallback(call,listener, Constant.SHOWBYUSER);
    }

    /*获取晒图列表根据俱乐部*/
    public void getShowByClub(int Club_id, final RetrofitListener listener){
        ShowService showService=retrofit.create(ShowService.class);
        Call call=showService.getShowByClub(Club_id);
        Callback<List<Show>> callback=new Callback<List<Show>>(){
            @Override
            public void onResponse(Call<List<Show>> call, Response<List<Show>> response ){
                List<Show> data=response.body();
                listener.onSuccess(data,2);
            }
            @Override
            public  void onFailure(Call<List<Show>> call, Throwable t){
                listener.onFail();
            }
        };
        call.enqueue(callback);
    }

    public Call<Show> insertShow(int user_id, String s_content,MultipartBody.Part file) {
        ShowService showService = retrofit.create(ShowService.class);
        return showService.insertShow(user_id,s_content,file);
    }


}
